<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>分配角色</title>
	<meta name="decorator" content="nblank"/>
</head>
<body>
<div class="content container">
	<h2 class="page-title">角色列表<small> 角色分配</small></h2>
	<section class="widget widget-tabs widget-table-overflow ">
		<header>
			<ul class="nav nav-tabs">
				<li><a href="${ctx}/sys/role/">角色列表</a></li>
				<li class="active"><a href="${ctx}/sys/role/assign?id=${role.id}"><shiro:hasPermission name="sys:role:edit">角色分配</shiro:hasPermission><shiro:lacksPermission name="sys:role:edit">人员列表</shiro:lacksPermission></a></li>
			</ul>
		</header>
		<div class="body tab-content">
			<table class="table table-striped table-condensed">
				<div class="row">
					<div class="col-md-4 col-sm-4 ">角色名称: <b>${role.name}</b></div>
					<div class="col-md-4 col-sm-4">归属机构: ${role.office.name}</div>
					<div class="col-md-4 col-sm-4">英文名称: ${role.enname}</div>
				</div>
				<br>
				<div class="row">
					<div class="col-md-4 col-sm-4">角色类型: ${role.roleType}</div>
					<c:set var="dictvalue" value="${role.dataScope}" scope="page" />
					<div class="col-md-4 col-sm-4">数据范围: ${fns:getDictLabel(dictvalue, 'sys_data_scope', '')}</div>
					<div class="col-md-4 col-sm-4">
						<form id="assignRoleForm" action="${ctx}/sys/role/assignrole" method="post" class="hide">
							<input type="hidden" name="id" value="${role.id}"/>
							<input id="idsArr" type="hidden" name="idsArr" value=""/>
						</form>
						<input id="assignButton" class="btn btn-primary" type="submit" value="分配角色"/>
					</div>
				</div>
			</table>
		</div>
			<br>
		<sys:message content="${message}"/>
		<div class="body tab-content">
			<table id="contentTable" class="table table-striped table-condensed">
				<thead><tr><th>归属公司</th><th>归属部门</th><th>登录名</th><th>姓名</th><th>电话</th><th>手机</th><shiro:hasPermission name="sys:user:edit"><th>操作</th></shiro:hasPermission></tr></thead>
				<tbody>
				<c:forEach items="${userList}" var="user">
					<tr>
						<td>${user.company.name}</td>
						<td>${user.office.name}</td>
						<td><a href="${ctx}/sys/user/form?id=${user.id}">${user.loginName}</a></td>
						<td>${user.name}</td>
						<td>${user.phone}</td>
						<td>${user.mobile}</td>
						<shiro:hasPermission name="sys:role:edit"><td>
							<a href="${ctx}/sys/role/outrole?userId=${user.id}&roleId=${role.id}" class="no-pjax"
                               onclick="confirmx('确认要将用户<b>[${user.name}]</b>从<b>[${role.name}]</b>角色中移除吗？', this.href);return false;">移除</a>
						</td></shiro:hasPermission>
					</tr>
				</c:forEach>
				</tbody>
			</table>
		</div>
	</section>
</div>
<script type="text/javascript">
	$("#assignButton").click(function(){

        bootbox.dialog({
            message: getIframe("${ctx}/sys/role/usertorole?id=${role.id}"),
            title: "分配角色 (通过选择部门，然后为列出的人员分配角色。)",
            size:"large",
            buttons: {
               cancel: {
                    label: "关闭",
                    callback: function () {

                    }
                }, clear: {
                    label: "清除已选",
                    callback: function () {
                        $(document).find("iframe")[0].contentWindow.clearAssign();
                        return false;
                    }
                },ok: {
                    label: "确定分配",
                    className: "btn-primary",
                    callback: function () {
                        var innerIframe = $(document).find("iframe")[0];
                        var pre_ids = innerIframe.contentWindow.pre_ids;
                        var ids = innerIframe.contentWindow.ids;
                        var message_pos = $(innerIframe).contents().find("#inner_message");
                        // 删除''的元素
                        if(ids[0]==''){
                            ids.shift();
                            pre_ids.shift();
                        }
                        if(pre_ids.sort().toString() == ids.sort().toString()){
                            message_pos.show();
                            message_pos.html("未给角色【${role.name}】分配新成员！", 'info');
                            return false;
                        };
                        // 执行保存
//                        loading('正在提交，请稍等...');
                        var idsArr = "";
                        for (var i = 0; i<ids.length; i++) {
                            idsArr = (idsArr + ids[i]) + (((i + 1)== ids.length) ? '':',');
                        }
                        $('#idsArr').val(idsArr);
                        $('#assignRoleForm').submit();
                    }
                }
            }
        });
	});
    function getIframe(url) {
        var newIframeObject = document.createElement("iframe");
        newIframeObject.src = url;
        newIframeObject.scrolling = "no";
        newIframeObject.frameBorder = 0;
        newIframeObject.width = "100%";
        newIframeObject.height = "400px";
        newIframeObject.style.border = "none";
        return newIframeObject;
    }
</script>
</body>
</html>
